<?php
require_once("DButil.php");
$course1=$_REQUEST["course1"];//课程编号 不可修改
$coursename1=$_REQUEST["coursename1"];//课程名称
$sql1="select courseName from t_course where courseName='{$coursename1}'";
$arr1=query($sql1)[0];//查询是否跟库中有一个名字相同,相同则有、否则无

$sql2="select courseName from t_course where courseId={$course1}";
$arr2=query($sql2)[0];//查出原本的名字

if($coursename1==""){
    $result=[
        "code" =>0,
        "msg" =>"课程名不空"
    ];
}

if((!$arr1 || $arr2['courseName']==$coursename1) && $coursename1!=""){
    $sql="update t_course set courseName='{$coursename1}' where courseId={$course1} ";
    $arr=update($sql);
    $result=[
        "code" =>2,
        "msg" =>"课程更新成功"
    ];
}
header("Content-Type:application/json;charset=utf-8");
echo json_encode($result);

?>